use :: libc;
extern "C" {
    pub type stat;
    pub type dirent;
    fn glob(
        __pattern: *const i8,
        __flags: i32,
        __errfunc: Option<unsafe extern "C" fn(*const i8, i32) -> i32>,
        __pglob: *mut glob_t,
    ) -> i32;
    fn globfree(__pglob: *mut glob_t);
    fn getpid() -> __pid_t;
    fn snprintf(_: *mut i8, _: u64, _: *const i8, _: ...) -> i32;
    fn fatal(_: *const i8, _: ...);
}
pub type __pid_t = i32;
pub type __size_t = u64;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct glob_t {
    pub gl_pathc: __size_t,
    pub gl_pathv: *mut *mut i8,
    pub gl_offs: __size_t,
    pub gl_flags: i32,
    pub gl_closedir: Option<unsafe extern "C" fn(*mut libc::c_void) -> ()>,
    pub gl_readdir: Option<unsafe extern "C" fn(*mut libc::c_void) -> *mut dirent>,
    pub gl_opendir: Option<unsafe extern "C" fn(*const i8) -> *mut libc::c_void>,
    pub gl_lstat: Option<unsafe extern "C" fn(*const i8, *mut stat) -> i32>,
    pub gl_stat: Option<unsafe extern "C" fn(*const i8, *mut stat) -> i32>,
}
#[no_mangle]
pub extern "C" fn getdtablecount() -> i32 {
    let mut path: [i8; 4096] = [0; 4096];
    let mut g: glob_t = glob_t {
        gl_pathc: 0,
        gl_pathv: std::ptr::null_mut::<*mut i8>(),
        gl_offs: 0,
        gl_flags: 0,
        gl_closedir: None,
        gl_readdir: None,
        gl_opendir: None,
        gl_lstat: None,
        gl_stat: None,
    };
    let mut n: i32 = 0 as i32;
    if (unsafe {
        snprintf(
            path.as_mut_ptr(),
            ::core::mem::size_of::<[i8; 4096]>() as u64,
            b"/proc/%ld/fd/*\0" as *const u8 as *const i8,
            getpid() as i64,
        )
    }) < 0 as i32
    {
        (unsafe { fatal(b"snprintf overflow\0" as *const u8 as *const i8) });
    }
    if (unsafe { glob(path.as_mut_ptr(), 0 as i32, None, &mut g) }) == 0 as i32 {
        n = g.gl_pathc as i32;
    }
    (unsafe { globfree(&mut g) });
    return n;
}
